package com.jzg.jcptadmin.adpter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.data.vo.ChooseResultData;
import com.jzg.jcptadmin.view.MyListView;

import java.util.List;

/**
 * author: guochen
 * date: 2016/11/8 16:09
 * email:
 */
public class ChooseResultAdapter extends BaseAdapter {
    private Context context;
    private List<ChooseResultData.DataBean> datas;
    final int TYPE_1 = 0;
    final int TYPE_2 = 1;
    private ViewHolderTitle viewHolderTitle;
    private ViewHolder viewHolder;

    public ChooseResultAdapter(Context context, List<ChooseResultData.DataBean> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }


    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position1, View convertView, ViewGroup parent) {

        if (convertView == null) {
            viewHolderTitle = new ViewHolderTitle();
            convertView = View.inflate(context, R.layout.choose_result_title, null);
            viewHolderTitle.title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolderTitle.listView = (MyListView) convertView.findViewById(R.id.my_listView);
            convertView.setTag(viewHolderTitle);
        } else {
            viewHolderTitle = (ViewHolderTitle) convertView.getTag();

        }
//设置数据
        viewHolderTitle = (ViewHolderTitle) convertView.getTag();
        viewHolderTitle.title.setText(datas.get(position1).getGroupName());
        final ChooseResultItemAdapter chooseResultItemAdapter = new ChooseResultItemAdapter(context, datas.get(position1).getGroupValue());
        viewHolderTitle.listView.setAdapter(chooseResultItemAdapter);
        viewHolderTitle.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if(datas.get(position1).getGroupValue().get(position).isSelect()){
                    datas.get(position1).getGroupValue().get(position).setSelect(false);
                }else{
                    initSelect(datas.get(position1).getGroupValue());
                    datas.get(position1).getGroupValue().get(position).setSelect(true);
                }
                chooseResultItemAdapter.notifyDataSetChanged();
            }

        });
        return convertView;
    }

    public class ViewHolder {

        public TextView result;
        public CheckBox checkBox;
        public LinearLayout ll_linear;

    }

    class ViewHolderTitle {
        public TextView title;
        public MyListView listView;

    }

    public void initSelect(List<ChooseResultData.DataBean.GroupValueBean> GroupValues ){
        for(int i=0;i< GroupValues.size();i++){
            GroupValues.get(i).setSelect(false);

        }
    }

}
